/***************************************************************************
*   Copyright (C) 2011 by Chuck Gao & Alex Liu                             *
*                                                                          *
*   This program is free software: you can redistribute it and/or modify   *
*   it under the terms of the GNU General Public License as published by   *
*   the Free Software Foundation, either version 3 of the License, or      *
*   (at your option) any later version.                                    *
*                                                                          *
*   This program is distributed in the hope that it will be useful,        *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
*   GNU General Public License for more details.                           *
*                                                                          *
*   You should have received a copy of the GNU General Public License      *
*   along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
*                                                                          *
*   Contact author: chuckgao.cg@gmail.com                                  *
*                   alex2202375@gmail.com                                  *
***************************************************************************/

import QtQuick 1.0

Rectangle {
    id: btn
    width: 260
    height: 80
    radius: 10

    property int index: -1
    property string titleText: ""

    Text {
        id: name
        anchors.centerIn: parent
        text: titleText
        //                font.family: "Freestyle Script"
        horizontalAlignment: Text.AlignHCenter
        verticalAlignment: Text.AlignVCenter
        font.pointSize: 20
    }

    state: 'show'

    // State is "show", enable launch subview
    // When state is "hide", show menu btn first(change state to "show")
    states: [
        State {
            name: "hide"
            PropertyChanges {
                target: btn
                x: menuGroup.menuOffset;
                opacity: 0.4
            }
        },
        State {
            name: "show"
            PropertyChanges {
                target: btn
                x: -(menuGroup.width - btn.width)/2;
                opacity: 0.8
            }
        }
    ]

    transitions: [
        Transition {
            from: "show"
            to: "hide"
            reversible: true
            PropertyAnimation {
                target: btn;
                properties: "x";
                easing.type: Easing.OutBack
                duration: 1200
            }
            PropertyAnimation {
                target: btn;
                properties: "opacity";
                duration: 1200
            }
        }
    ]

    MouseArea {
        anchors.fill: parent
        onClicked: {
            console.debug("MenuBtn Clicked, index:", index)
            if('show' == btn.state)
            {
                mainMenu.launchCookingSubView(index)
            }else{
                // Hide other menu btns first
                menuGroup.hideMenuBtns()
                btn.state = "show"
            }
        }
    }
}
